package cate.game.role.bag.item;

import cate.common.table.item.IBagItemTpl;
import cate.game.GameBody;
import cate.game.doc.ItemConfigDocMaker;
import cate.game.play.support.PlayBuildContext;
import cate.game.role.Role;
import cate.game.role.RoleDependent;
import cate.game.table.ItemConfigHelper;
import cate.game.util.GameKit;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "道具数据")
public abstract class BaseBagItem extends RoleDependent{
    @NoteField(value = "唯一id")
    public String uid;

    @NoteField(value = "模板id")
    public int tid;

    @NoteField(value = "数量")
    public long num;

    @NoteField(value = "类型")
    public byte type;

    public BaseBagItem(){}

    public BaseBagItem(Role role, byte type, int tid, long num){
        super(role);
        this.type = type;
        this.tid = tid;
        this.num = num;
        this.uid = GameKit.uid();
    }

    public void addNum(long num){
        this.num += num;
    }

    public boolean moreThan(long num){
        return this.num > num;
    }

    public abstract IBagItemTpl getTpl(PlayBuildContext ctx);

    public abstract IBagItemTpl getTpl(GameBody game);

    public void copy(BaseBagItem cp) {
        cp.type = this.type;
        cp.uid = this.uid;
        cp.tid = this.tid;
        cp.num = this.num;
    }


    public String toName(PlayBuildContext ctx) {
        try {
            ItemConfigDocMaker.ItemConfigDoc doc = ItemConfigHelper.instance.findItemConfigDoc(tid);
            if (doc != null) {
                return doc.name;
            }
            return getTpl(ctx).toName();
        } catch (Exception e) {
            return e.getMessage();
        }
    }

    public String toDetail() {
        return "";
    }

    public boolean unique() {
        return false;
    }
}
